<template>
	<view class="my_dangan">
		<view class="m_header">
			<changeOrgs ref="orgs" @listData="listData" :bindType="bindType"></changeOrgs>
		</view>
		<view class="cardList">
			<scroll-view :style="{height: height}" scroll-y="true" class="scroll-Y" @scrolltoupper="upper" @scrolltolower="lower"
			@scroll="scroll">
				<cardBox :dataList="qingList" @jiebang="jiebang" @jumpCard="jumpCard"></cardBox>
			</scroll-view>
		</view>
		<mcModal :isShow="showMcModal" :content="content" :title="title" @cancel='bb()' :inp="false" @ok='cc()' :okBtn='okBtn'></mcModal>
	</view>
</template>

<script>
	import {UnStudentBindEmp} from '../../common/api/index.js'
	import {_showToast} from '../../common/js/util.js'
	import changeOrgs from '../../components/changeOrgs.vue'
	import cardBox from '../../components/card-box.vue'
	import mcModal from '../../components/custom-modal/custom-modal.vue'
	export default {
		onShow: function(){
			let _that = this;
			uni.getSystemInfo({
				success: function (res) {
					_that.height = res.windowHeight - 120 + 'px';
				}
			})
		},
		data() {
			return {
				qingList: [],
				height: 0,
				orgId: '',
				bindType: 1,
				showMcModal: false,
				content: '',
				title: '',
				okBtn: '',
				ite: {},
				item: {}
			}
		},
		components: {
			changeOrgs,
			cardBox,
			mcModal
		},
		methods: {
			bb() {
				this.showMcModal = false
			},
			cc() {
				this.showMcModal = false
				_showToast('解绑中...')
				UnStudentBindEmp({
					empId: this.item.empId,
					bindType: this.ite.bindType == 0 ? 0 : 1,
					userId: uni.getStorageSync('s_userId')
				}).then(res => {
					if(res.resultCode == 0) {
						uni.hideLoading()
						this.$refs.orgs._queryStudentCardBalance()
					} else {
						uni.hideLoading()
					}
				}).catch(err => {
					uni.hideLoading()
					console.log(err)
				})
			},
			upper() {},
			scroll() {},
			lower() {},
			listData(arr, orgId) {
				this.qingList = arr
				this.orgId = orgId
			},
			jumpCard(empName, arr) {
				uni.navigateTo({
					url: '/packageCard/card/danganCard?arrObj=' + encodeURIComponent(JSON.stringify(arr)) + '&empName=' + empName + '&hasSet=' + true
				})
			},
			jiebang(ite, item) {
				this.title = '温馨提示'
				this.content = '您好！解除绑定将无法使用部分功能'
				this.okBtn = '确认'
				this.ite = ite
				this.item = item
				this.showMcModal = true
			}
		}
	}
</script>

<style lang="scss">
	page {
		overflow: hidden;
	}
	.my_dangan {
		background-color: rgb(243, 243, 243);
		height: 100vh;
		overflow: hidden;
		.m_header {
			width: 100vw;
			height: 390rpx;
			background-image: url('');
			background-size: 100%;
			background-repeat: no-repeat;
			display: flex;
			justify-content: center;
		}
		.cardList {
			padding: 0 30rpx 20rpx 30rpx;
			width: 92%;
			position: absolute;
			top: 230rpx;
		}
	}
</style>